package org.dromara.common.translation.core.impl;

import lombok.AllArgsConstructor;
import org.dromara.common.core.service.ProductService;
import org.dromara.common.translation.annotation.TranslationType;
import org.dromara.common.translation.constant.TransConstant;
import org.dromara.common.translation.core.TranslationInterface;

/**
 * OSS翻译实现
 *
 * @author Lion Li
 */
@AllArgsConstructor
@TranslationType(type = TransConstant.PRODUCT_ID_TO_NAME)
public class ProductIdTranslationImpl implements TranslationInterface<String>
{

    private final ProductService productService;

    @Override
    public String translation(Object key, String other)
    {
        if (key instanceof Long id)
        {
            if (!other.isEmpty() && "type".equals(other))
            {
                return productService.selectProductTypeByProductId(id);
            }
            else
            {
                return productService.selectProductNameById(id);
            }

        }
        else if (key instanceof String id)
        {
            return productService.selectProductNameById(Long.valueOf(id));
        }
        return null;
    }
}
